package controllerLayer;
import modelLayer.*;
import java.util.*;

/**
 * A simple controller for the program
 * @author A-Leonard
 * @version ALPHA
 */

public class PersonCTR {
    public static void createPerson(int id ,String name, String address, String zip, String city, String phone){
        Person p = new Person(id, name, address, zip, city, phone);
        PersonContainer.getInstance().addPerson(p);
    }
    /**
     * This method finds a person by his id
     */
    public static Person findPerson(int id){
        return PersonContainer.getInstance().getPerson(id);
    }
    /**
     * This method updates person's information.
     * If the field is blank you have to set the new parameter.
     * @param name
     * @param address
     * @param zip
     * @param city
     * @param phone
     */
    public void updatePerson(Person p , String name, String address, String zip, String city, String phone){
        
        if(!name.equals("-"))
            p.setName(name);
        if(!address.equals("-"))
            p.setAddress(address);
        if(!zip.equals("-"))
            p.setPostalCode(zip);
        if(!city.equals("-"))
            p.setCity(city);
        if(!phone.equals("-"))
            p.setPhone(phone);
        
        
    }
    
    public void show(int id){
        if(id>0&&id<=PersonContainer.getInstance().getAll().size())
        {
        Person p = findPerson(id);
        p.showInfo();
        }
        else
        {
            System.out.println("Enter a valid id");
        }
    }
    
    public void showAll(){
        ArrayList<Person> pers = PersonContainer.getInstance().getAll();
        for(Person p : pers ){
            p.showInfo();
        }
        if(pers.size()==0)
        System.out.println("You don't have any friends.");
    }
    
    public void delete(int id){
        if(id>0&&id<=PersonContainer.getInstance().getAll().size())
        {
        Person p = findPerson(id);
        PersonContainer.getInstance().deletePerson(p);
        }
        else
        {
            System.out.println("Enter a valid id");
        }
    
    }
}
